package com.fanqj.resilience4j.config;

import io.github.resilience4j.common.circuitbreaker.configuration.CircuitBreakerConfigCustomizer;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * 自定义配置resilience4j组件对象
 * @author <a href="mailto:fanqijin@wxchina.com">fanqj</a>
 * @Date 2021年01月27日 14:51
 * @Version 6.4.1
 */
@Component
public class Resilience4jConfig {

    /**
     * 覆盖yml配置的backendA断路器
     * @return
     */
    @Bean
    public CircuitBreakerConfigCustomizer testOverwrite() {
        return CircuitBreakerConfigCustomizer
                .of("backendA", builder ->
                        builder.slidingWindowSize(10)
                                .failureRateThreshold(50)
                                .minimumNumberOfCalls(10));
    }

   /* @Bean
    public List<CircuitBreakerConfigCustomizer> listCustomizer() {
        List<CircuitBreakerConfigCustomizer> list = new ArrayList<>();
        list.add(CircuitBreakerConfigCustomizer.of("backendC", builder -> builder.minimumNumberOfCalls(10)));
        return list;
    }*/

}
